package com.aaa.dao.impl;

import com.aaa.dao.BaseDao;
import com.aaa.dao.UserDao;
import com.aaa.entity.User;

import java.util.List;
import java.util.Map;

public class UserDaoImpl implements UserDao {

    BaseDao baseDao = BaseDao.getInstance();

    @Override
    public int addUser(User user) {

        String sql = "insert into user (cardId,userName,status,phone,idCard,sex,address,createdTime,momo,area)"+
                "values (?,?,?,?,?,?,?,?,?,?)";

        Object[] params = {user.getCardId(),user.getUserName(),user.getStatus(),user.getPhone(),user.getIdCard(),user.getSex()
                ,user.getAddress(),user.getCreatedTime(),user.getMomo(),user.getArea()};

        return baseDao.executeInsert(sql,params);
    }

    @Override
    public List<Map<String, Object>> getDataByNearYear() {
        String sql = "select COUNT(*) amount,SUBSTRING(createdTime FROM 6 FOR 2) month from `user` GROUP BY SUBSTRING(createdTime FROM 6 FOR 2)";
        return baseDao.query(sql,null);
    }


}
